frappe.ui.form.on('Tongtool Settings', {
    refresh: function(frm) {
        // 添加测试连接按钮
        frm.add_custom_button(__('Test API Connection'), function() {
            frm.call('test_connection');
        }, __('Actions'));
        
        // 添加手动同步按钮
        frm.add_custom_button(__('Sync Orders Now'), function() {
            frm.call('sync_now');
        }, __('Actions'));
        
        // 添加刷新所有订单按钮
        frm.add_custom_button(__('Refresh All Orders'), function() {
            frappe.confirm(
                __('This will refresh all orders with missing data. Continue?'),
                function() {
                    frm.call('refresh_all_orders');
                }
            );
        }, __('Actions'));
    },
    
    test_connection_button: function(frm) {
        frm.call('test_connection');
    },
    
    refresh_now_button: function(frm) {
        frappe.confirm(
            __('This will refresh all orders with missing data. Continue?'),
            function() {
                frm.call('refresh_all_orders');
            }
        );
    }
});